﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AppSettings.ascx.cs" Inherits="CMS.Web.ListManager.AppSettings" %>
<script language="javascript" src="~/Common/util.js"></script>
<table align="center" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
    width="96%">
    <tr>
        <td align="left" height="4px" width="100%">
        </td>
    </tr>
</table>
<table id="tblProcess" align="center" border="0" cellpadding="0" cellspacing="0"
    class="Table_Border" style="border-collapse: collapse" width="96%">
    <tr class="Row_Document_Title">
        <td colspan="2">
            <table border="0" width="100%">
                <tr>
                    <td width="40%">
                        <asp:Label ID="lblEdit" runat="server"></asp:Label></td>
                    <td align="right" width="60%">
                        <asp:Label ID="lblMsg" runat="server" ForeColor="#FF0000"></asp:Label></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td class="Col_Left" width="28%">
            Máy chủ CSDL <font color="#ff0000">(*)</font>:</td>
        <td class="Col_Right" width="72%">
            <asp:TextBox ID="txtDataSource" runat="server" cssClass="TextBox" MaxLength="50" Width="200px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="Col_Left">
            Tên CSDL <font color="#ff0000">(*)</font>:</td>
        <td class="Col_Right">
            <asp:TextBox ID="txtDatabase" runat="server" cssClass="TextBox" MaxLength="50" Width="200px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="Col_Left">
            Tài khoản CSDL <font color="#ff0000">(*)</font>:</td>
        <td class="Col_Right">
            <asp:TextBox ID="txtUserID" runat="server" cssClass="TextBox" MaxLength="20" Width="200px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="Col_Left">
            Mật khẩu:</td>
        <td class="Col_Right">
            <asp:TextBox ID="txtPassword" runat="server" cssClass="TextBox" MaxLength="20" Width="200px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="Col_Left">
            Thư mục Upload <font color="#ff0000">(*)</font>:</td>
        <td class="Col_Right">
            <asp:TextBox ID="txtUploadPath" runat="server" cssClass="TextBox" MaxLength="250" Width="480px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="Col_Left">
            E-mail <font color="#ff0000">(*)</font>:</td>
        <td class="Col_Right">
            <asp:TextBox ID="txtEmail" runat="server" cssClass="TextBox" MaxLength="100" Width="200px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="Col_Left">
            Mật khẩu E-mail <font color="#ff0000">(*)</font>:</td>
        <td class="Col_Right">
            <asp:TextBox ID="txtPassEmail" runat="server" cssClass="TextBox" MaxLength="100" Width="200px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td class="Col_Left">
            Cấp địa bàn:</td>
        <td class="Col_Right">
            <asp:DropDownList ID="drpDiaBan" runat="server" cssClass="TextBox" DataTextField="TenDiaBan" DataValueField="ID" Width="300px"></asp:DropDownList>
             <asp:HiddenField ID="hidMaDiaBan" runat="server" /> 
            <asp:HiddenField ID="hidTenDiaBan" runat="server" />
        </td>
    </tr>    
    <tr class="Row_Button">
        <td align="center" height="22">
        </td>
        <td style="text-align:left;">
            <asp:Button ID="btnOK" runat="server" CssClass="Button" OnClick="btnOK_Click" Text="Lưu"
                Width="70px" />
            <asp:Button ID="btnSave" runat="server" CssClass="Button" OnClick="btnOK_Click" Text="Lưu" style="display:none"
                Width="70px" />
            &nbsp;
        </td>
    </tr>
</table>
<table align="center" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
    width="96%">
    <tr><td align="left" height="4px" width="100%"></td></tr>
</table>
<script language="javascript">
<%if(IsFinishUpdate){%>
   alert("Cập nhật cấu hình hệ thống thành công. Hệ thống sẽ tự khởi động lại!"); 
   window.location.href = 'LogIn.aspx'; 
<%}%>

function checkValidationForm(){
    strMsg = "";
    strMsg += isValid("<%=txtDataSource.ClientID %>",50,1,spec,1,0,"Máy chủ CSDL");
    strMsg += isValid("<%=txtDatabase.ClientID %>",50,1,spec,1,0,"Tên CSDL");
    strMsg += isValid("<%=txtUserID.ClientID %>",20,1,spec,1,0,"Tài khoản CSDL");
	        
    var uploadFolder = $('#<%=txtUploadPath.ClientID %>').val();

    var drpDiaBan = document.getElementById("<%=drpDiaBan.ClientID%>");
    
    if(drpDiaBan.selectedIndex>=0){
        $('#<%=hidMaDiaBan.ClientID %>').val(drpDiaBan.value);
        $('#<%=hidTenDiaBan.ClientID %>').val(drpDiaBan.options[drpDiaBan.selectedIndex].text);
    }
    CMS.Presenters.AppSettingsPresenter.CheckExists(uploadFolder,function(response){
        var result = response.value;
        if(result!=null){
            if(!result){
                strMsg += '\n - Thư mục Upload không tồn tại. Xin vui lòng nhập lại!';
            }            
        }
        if (strMsg!=""){
            strMsg = strMsg.substr(1);
            alert(strMsg);
            return false;
        }else{
            $$('<%=btnSave.ClientID %>').click();
        }
    });       
}
</script>